
package com.jf.cloud.product.controller.admin;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.dto.SpuConsignmentChangeDTO;
import com.jf.cloud.product.model.SpuConsignmentChange;
import com.jf.cloud.product.service.SpuConsignmentChangeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商家代销商品基本信息相对于供应商品是否改变
 *
 * @author zz
 * @date 2022-08-11 22:21:10
 */
@RestController("multishopSpuConsignmentChangeController")
@RequestMapping("/m/spu_consignment_change")
@Tag(name = "商家代销商品基本信息相对于供应商品是否改变")
public class SpuConsignmentChangeController {

    @Autowired
    private SpuConsignmentChangeService spuConsignmentChangeService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取商家代销商品基本信息相对于供应商品是否改变列表" , description = "分页获取商家代销商品基本信息相对于供应商品是否改变列表")
    public ServerResponseEntity<PageVO<SpuConsignmentChange>> page(@Valid PageDTO pageDTO) {
        PageVO<SpuConsignmentChange> spuConsignmentChangePage = spuConsignmentChangeService.page(pageDTO);
        return ServerResponseEntity.success(spuConsignmentChangePage);
    }

    @GetMapping
    @Operation(summary = "获取商家代销商品基本信息相对于供应商品是否改变" , description = "根据consignmentChangeId获取商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<SpuConsignmentChange> getByConsignmentChangeId(@RequestParam Long consignmentChangeId) {
        return ServerResponseEntity.success(spuConsignmentChangeService.getByConsignmentChangeId(consignmentChangeId));
    }

    @PostMapping
    @Operation(summary = "保存商家代销商品基本信息相对于供应商品是否改变" , description = "保存商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> save(@Valid @RequestBody SpuConsignmentChangeDTO spuConsignmentChangeDTO) {
        SpuConsignmentChange spuConsignmentChange = mapperFacade.map(spuConsignmentChangeDTO, SpuConsignmentChange.class);
        spuConsignmentChange.setConsignmentChangeId(null);
        spuConsignmentChangeService.save(spuConsignmentChange);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新商家代销商品基本信息相对于供应商品是否改变" , description = "更新商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> update(@Valid @RequestBody SpuConsignmentChangeDTO spuConsignmentChangeDTO) {
        SpuConsignmentChange spuConsignmentChange = mapperFacade.map(spuConsignmentChangeDTO, SpuConsignmentChange.class);
        spuConsignmentChangeService.update(spuConsignmentChange);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除商家代销商品基本信息相对于供应商品是否改变" , description = "根据商家代销商品基本信息相对于供应商品是否改变id删除商家代销商品基本信息相对于供应商品是否改变")
    public ServerResponseEntity<Void> delete(@RequestParam Long consignmentChangeId) {
        spuConsignmentChangeService.deleteById(consignmentChangeId);
        return ServerResponseEntity.success();
    }
}
